package cn.hsw.platform.core.base;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * 全局模型
 * @author 李子木
 * @date 2020-10-28
 */
@Getter
@Setter
@Entity(name = "hsw_base_model")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@EntityListeners(AuditingEntityListener.class)
@Where(clause = BaseConstant.NOT_DELETE)
public class BaseModel {

    @Id
    @GeneratedValue(generator = "SnowFlakeIdGenerator",
            strategy = GenerationType.SEQUENCE)
    @GenericGenerator(
            name = "SnowFlakeIdGenerator",
            strategy = "cn.hsw.platform.core.configure.SnowFlakeIdGeneratorConfig"
    )
    private Long pid;
    /**
     * 创建时间
     */
    @JSONField(name = "create_time",format = "yyyy-MM-dd HH:mm:ss")
    @CreatedDate
    private Date createTime;

    /**
     * 最后一次修改时间
     */
    @JSONField(name = "last_update_time",format = "yyyy-MM-dd HH:mm:ss")
    @LastModifiedDate
    private Date lastUpdateTime;

    /**
     * 创建者
     */
    @JSONField(serialize = false)
    private Long createBy;

    /**
     * 修改者
     */
    @JSONField(serialize = false)
    private Long updateBy;

    /**
     * 备注
     */
    private String remark;

    /**
     * 删除字段
     */
    @JSONField(serialize = false)
    private int isSoftDel;
}
